/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package database;

import java.sql.Array;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

/**
 *
 * @author Rick
 */
public class DBTestDriver {

    static ConnectionDAO connDAO;
    static VisualizationDAO visualDAO;
    static UsedDAO usedDAO;
    static int autoID;

    public static void main(String[] args){
        //create the required DAO factory
        DAOfactory mysqlFactory =
                DAOfactory.getDAOfactory(DAOfactory.MYSQL);

        //create a DAO
        connDAO = mysqlFactory.getConnectionDAO();
        visualDAO = mysqlFactory.getVisualizationDAO();
        usedDAO = mysqlFactory.getUsedDAO();

        //Connection
        runConnection();
        //Visualization
        //runVisualization();
        //Used
        runUsed();

        //test Queries
        runCountryCityName();

        runNameCountryCity();

        runCountryCityUsername();

    }

    static boolean  insertSuccess;
    
    public static void runConnection(){

        autoID = connDAO.addConnection("homeServer",
                "168.192.1.100", "lachapellerg@gmail.com", "Appleton", "Midwest", "USA");

        //visualDAO.findVisualization("Rick LaChszjpfoij");
    }

    public static void runVisualization(){

        insertSuccess = visualDAO.insertVisualization("B-Tree");
    }
    
    private static String getDateTime() {
        DateFormat dateFormat = new SimpleDateFormat("MM/dd/yy");
        Date date = new Date();
        return dateFormat.format(date);
    }

    public static void runUsed(){

        usedDAO.addUsage(autoID, "04/16/2012", "Empty List");
    }

    public static void runCountryCityUsername(){
        DBQueries dbQueries = new  DBQueries();
        ResultSet rs = dbQueries.getCountryCityUsername();

        ArrayList<Integer> visualCount = new ArrayList<Integer>();
        ArrayList<String> countryList = new ArrayList<String>();
        ArrayList<String> cityList = new ArrayList<String>();
        ArrayList<String> usernameList = new ArrayList<String>();
        ArrayList<String> timeList = new ArrayList<String>();

        try{
            //rs.next();
            int index = 0;
            while(rs.next()){
                visualCount.add(rs.getInt(1));
                countryList.add(rs.getString("country"));
                cityList.add(rs.getString("city"));
                usernameList.add(rs.getString(4));
                timeList.add(rs.getString("timeStamp"));
                index++;
            }

            for(int i = 0; i < countryList.size(); i++){
                System.out.println(visualCount.get(i) + "\t" + countryList.get(i) + "\t"+
                        cityList.get(i) + "\t" + usernameList.get(i) + "\t" + timeList.get(i));
            }
            rs.close();
        }catch(SQLException ex){
            System.out.println("SQL Error " + ex);
            ex.printStackTrace();
        }

    }

    public static void runNameCountryCity(){
        DBQueries dbQueries = new  DBQueries();
        ResultSet rs = dbQueries.getNameCountryCity();

        ArrayList<Integer> visualCount = new ArrayList<Integer>();
        ArrayList<String> countryList = new ArrayList<String>();
        ArrayList<String> cityList = new ArrayList<String>();
        ArrayList<String> visualNameList = new ArrayList<String>();
        ArrayList<String> timeList = new ArrayList<String>();


        try{
            //rs.next();
            int index = 0;
            while(rs.next()){
                visualCount.add(rs.getInt(1));
                visualNameList.add(rs.getString("visualName"));
                countryList.add(rs.getString("country"));
                cityList.add(rs.getString("city"));
                timeList.add(rs.getString("timeStamp"));
                index++;
            }

            for(int i = 0; i < countryList.size(); i++){
                System.out.println(visualCount.get(i) + "\t" + visualNameList.get(i) +"\t"+
                       countryList.get(i) + "\t" + cityList.get(i) + "\t" + timeList.get(i));
            }

            rs.close();
        }catch(SQLException ex){
            System.out.println("SQL Error " + ex);
            ex.printStackTrace();
        }

    }

    public static void runCountryCityName(){
        DBQueries dbQueries = new DBQueries();
        ResultSet rs = dbQueries.getCountryCityName();

        ArrayList<Integer> visualCount = new ArrayList<Integer>();
        ArrayList<String> countryList = new ArrayList<String>();
        ArrayList<String> cityList = new ArrayList<String>();
        ArrayList<String> visualNameList = new ArrayList<String>();
        ArrayList<String> timeList = new ArrayList<String>();


        try{
            //rs.next();
            int index = 0;
            while(rs.next()){
                visualCount.add(rs.getInt(1));
                countryList.add(rs.getString("country"));
                cityList.add(rs.getString("city"));
                visualNameList.add(rs.getString("visualName"));
                timeList.add(rs.getString("timeStamp"));
                index++;
            }

            for(int i = 0; i < countryList.size(); i++){
                System.out.println(visualCount.get(i) + "\t" + countryList.get(i) +"\t"+
                        cityList.get(i) +"\t"+
                        visualNameList.get(i) + "\t" + timeList.get(i));
            }
            rs.close();
        }catch(SQLException ex){
            System.out.println("SQL Error " + ex);
            ex.printStackTrace();
        }
    }
}
